package com.xinqi.modules.sys.rotation.controller.admin;

import com.xinqi.common.base.constants.ServiceNameConstants;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.common.core.enums.RotationImagePositionEnum;
import com.xinqi.common.core.enums.RotationImageTypeEnum;
import com.xinqi.common.log.syslog.annotation.Log;
import com.xinqi.common.log.syslog.enums.BusinessType;
import com.xinqi.common.log.syslog.enums.OperatorType;
import com.xinqi.modules.sys.rotation.dto.req.RotationImageCreateDTO;
import com.xinqi.modules.sys.rotation.dto.req.RotationImageDeleteDTO;
import com.xinqi.modules.sys.rotation.dto.req.RotationImageEnableDTO;
import com.xinqi.modules.sys.rotation.dto.req.RotationImageQueryDTO;
import com.xinqi.modules.sys.rotation.dto.req.RotationImageUpdateDTO;
import com.xinqi.modules.sys.rotation.dto.rsp.RotationImageResultDTO;
import com.xinqi.modules.sys.rotation.service.RotationImageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * ADMIN -- 系统轮播图
 *
 * @author: yyzhenn
 * @date: 2023/04/23
 */
@Tag(name = "Admin-系统轮播图", description = "系统轮播图Admin接口")
@Validated
@RestController
@RequestMapping("/admin/rotation-image")
@RequiredArgsConstructor
public class RotationImageAdminController {
    private final RotationImageService rotationImageService;

    @Operation(summary = "轮播图类型-枚举列表")
    @GetMapping("/type/list")
    public R<List<Map<String, String>>> typeList() {
        return R.data(RotationImageTypeEnum.getSelectList());
    }

    @Operation(summary = "轮播图位置-枚举列表")
    @GetMapping("/position/list/{type}")
    public R<List<Map<String, String>>> positionList(@NotEmpty(message = "{rotation.image.type.not.blank}") @PathVariable("type") String type) {
        return R.data(RotationImagePositionEnum.getSelectList(type));
    }

    @Operation(summary = "系统轮播图-分页")
    @GetMapping("/page")
    public R<PageInfo<RotationImageResultDTO>> page(@ParameterObject RotationImageQueryDTO dto) {
        PageInfo<RotationImageResultDTO> page = rotationImageService.page(dto, dto);
        return R.data(page);
    }

    @Operation(summary = "系统轮播图-详情")
    @GetMapping("/info/{id}")
    public R<RotationImageResultDTO> info(@NotNull(message = "{rotation.image.id.not.blank}") @PathVariable("id") Long id) {
        RotationImageResultDTO dto = rotationImageService.findById(id);
        return R.data(dto);
    }

    @Operation(summary = "系统轮播图-新增")
    @PostMapping("/add")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 新增系统轮播图", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    public R<Long> insert(@Validated @RequestBody RotationImageCreateDTO dto) {
        return R.data(rotationImageService.insert(dto));
    }

    @Operation(summary = "系统轮播图-修改")
    @PostMapping("/edit")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 修改系统轮播图", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R<Boolean> edit(@Validated @RequestBody RotationImageUpdateDTO dto) {
        return R.data(rotationImageService.updateById(dto));
    }

    @Operation(summary = "系统轮播图-启用/禁用")
    @PostMapping("/enable")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 启用/禁用系统轮播图", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R<Boolean> enable(@Validated @RequestBody RotationImageEnableDTO dto) {
        return R.data(rotationImageService.enable(dto));
    }

    @Operation(summary = "系统轮播图-删除")
    @PostMapping("/remove")
    @Log(title = ServiceNameConstants.XQ_SYS + " -- 删除系统轮播图", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R<Boolean> delete(@Validated @RequestBody RotationImageDeleteDTO dto) {
        return R.data(rotationImageService.deleteById(dto));
    }
}
